<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    let arr1 = [
        {totlehour:"50", state:1,project:"1"},
        {totlehour:"40",state:2,project:"1"},
        {totlehour:"30",state: 3,project:"1"},
        {totlehour:"20",state: 1,project:"2"},
        {totlehour:"20",state: 1,project:"3"}

        ]
    let arr2 = [
        {
            totlehour1:'',
            totlehour2:'',
            totlehour3:''
        }
        ]
    arr1.forEach((item,index)=>{
        console.log(index)
        arr2[0]['totlehour'+(index)] = item.totlehour
    })
    console.log(arr2)

    function convert (arr1) {
        var map1 = {};
        while(arr1.length) {
            let current = arr1.pop(); // 会影响原数组
            map1[current.project] = map1[current.project] || [];
            map1[current.project].push(current);
        }
        return Object.keys(map1).map(key => map1[key]);
    }
    var arrayTwo = convert(arr1)

    // for (let i=0; i<arrayTwo.length; i++) {
    //     console.log(i)
    //     for (let j=0; j < arrayTwo[i].length; j++) {
    //         arr2[i]['totlehour' + (i + 1)] = arrayTwo[i]
    //     }
    // }





    var ages = [32, 33, 16, 40];
    function checkAdult(age) {
        return age >= 18;
    }
    function myFunction() {
        alert(ages.filter(checkAdult));
    }
    myFunction()
   // const groupBy = (list, fn) => {
   //      const groups = [];
   //      list.forEach(function (o) {
   //          const group = JSON.stringify(fn(o));
   //          groups[group] = groups[group] || [];
   //          groups[group].push(o);
   //      });
   //      return groups;
   //  }
   //
   //  let groupData = groupBy(arr1, (link) => {
   //      return link.project
   //  })
   //  console.log(groupData)
   //  console.log(groupData[0].length)
</script>
</body>
</html>
